package com.liuyu.common.framework.util

import cn.hutool.cron.CronUtil
import com.liuyu.common.framework.iinsure.ApplicationTests
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.context.SpringBootTest
import spock.lang.Specification

/**
 * ${DESCRIPTION}
 * @author: liuyu
 * @date: 2023/5/17 12:36
 * @version: ${VERSION}
 */
@SpringBootTest(classes = ApplicationTests)
@AutoConfigureMockMvc

//@Transactional
class CronUtilTests extends Specification {


    def "判断是否是合法Cron表达式"() {
        given:
        when:
        CronUtil.is
        String result = CronUtils.isValid(cronExpression)
        then:
        with(result) {
            result == status
        }
        where:
        cronExpression   || status
        "0/10 * * * * ?" || "true"
        "0 8 # 0 8 ? *"  || "false"
    }

    def "判断Cron表达式并给出描述"() {
        given:
        when:
        String result = CronUtils.getInvalidMessage(cronExpression)
        then:
        with() {
            result == status
        }
        where:
        cronExpression   || status
        "0/10 * * * * ?" || null
        "0 8 # 0 8 ? *"  || "Unexpected character: #"
    }

    def "返回下一个Cron表达式执行时间"() {
        given:
        when:
        String result = CronUtils.getNextExecution(cronExpression)
        then:
        with() {
            println result
        }
        where:
        cronExpression    | _
        "0/10 30 * * * ?" | _
    }

}